<?php

namespace App\Http\Controllers;

use App\Consumer;
use App\MakeTable\Table;
use App\Redict\Success;
use Illuminate\Http\Request;
use Gate;

class ConsumerController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $pagename = '用户管理';
        $modelurl = 'consumers';
        $tablecate = ['tablecate'=>'用户'];
        $headname = ['用户名','头像','联系人电话','性别','密码','奖品积分','关注','粉丝','消息数量','注册时间','操作'];
        $tablehead = ['nickname','avatar','contact_tele','sex','password','award_integration','follower_count','followed_count','twitters_count','created_at','id'];
        if(Gate::denies('root_Admin_consumer')) {
            $headname = ['用户名','头像','联系人电话','性别','密码','奖品积分','关注','粉丝','消息数量','状态'];
            $tablehead = ['nickname','avatar','contact_tele','sex','password','award_integration','follower_count','followed_count','twitters_count','status'];
        }
        $consumerytable = new Table($tablehead,$page = 8);
            $model = $consumerytable->viewdata(Consumer::class);
            $models = $consumerytable->viewpagedata(Consumer::class);
        return view('admin.home.tableshow',compact('tablecate','model','tablehead','models','headname','pagename','modelurl'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //删除
        Consumer::destroy($id);
        return Success::back();
    }
}
